//package com.swd.order.util;
//
//
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.swd.order.service.WxService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.http.HttpEntity;
//import org.apache.http.util.EntityUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@Component
//@EnableScheduling   // 2.开启定时任务
//@Slf4j
//public class TimingTask {
//
//    @Autowired
//    private WxUtil wxUtil;
//    @Autowired
//    private WxService wxService;
//    @Autowired
//    private WxProperties wxProperties;
//    @Autowired
//    private ObjectMapper objectMapper;
//
//    @Scheduled(fixedRate = 30 * 60 * 1000) //每个小时都执行一次
//    public void accessTokenResert(){
//
//        log.info("定时重置access_token");
//
//        Map<String, String> map = new HashMap<>();
//        map.put("grant_type", wxProperties.getGrant_type());
//        map.put("appid", wxProperties.getAppid());
//        map.put("secret", wxProperties.getSecret());
//
//        JsonNode jsonNode = null;
//
//        try {
//            HttpEntity request = HttpUtil.getRequest(wxProperties.getGetAccessTokenUrl(), map);
//            jsonNode = objectMapper.readTree(EntityUtils.toString(request));
//        } catch (Exception e) {
//            log.error("获取getAccessToken失败", e);
//        }
//
//        log.info(jsonNode.toString());
//        if (StringUtils.isEmpty(jsonNode.get("access_token").asText())) {
//            log.error("获取getAccessToken失败{}", jsonNode.toString());
//            return;
//        }
//        wxUtil.setAccessToken(jsonNode.get("access_token").asText());
//
//    }
//}
